/**
 * 
 */
package com.example.queue.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.example.queue.dto.EmployeeBean;
import com.example.queue.service.EmployeeService;

/**
 * @author sunaina.sharma
 * 
 */
@Controller
public class EmployeeController {

	@Autowired
	EmployeeService employeeService;

	/**
	 * This method is used to display the form view for add employee
	 * functionality
	 * 
	 * @param employeeBean
	 * @param result
	 * @return
	 */
	@RequestMapping(value = "/addemployee", method = RequestMethod.GET)
	public ModelAndView showView(
			@ModelAttribute("employeeBean") EmployeeBean employeeBean,
			BindingResult result) {
		return new ModelAndView("empdetails");
	}

	/**
	 * This method is used to submit employee details
	 * 
	 * @param employeeBean
	 * @param result
	 * @return
	 */
	@RequestMapping(value = "/addemployee", method = RequestMethod.POST)
	public ModelAndView addContact(
			@ModelAttribute("employeeBean") EmployeeBean employeeBean,
			BindingResult result) {
		try {
			employeeService.addEmployeeDetails(employeeBean);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return new ModelAndView("success");
	}

}
